<?php 
## include required files
/*******************************/
require_once '../model/country.php';
/*******************************/
## Create Objects
/*******************************/
$countryObj = new Model_Country();
/*******************************/

if(isset($_POST['addcountry_btn'])) {	
	## apply PHP validation for required filed
	if(trim($_POST['countryname']) != '' && trim($_POST['ciso_code']) != '') {
		extract($_POST);		
		$countryAddArray['country_id']   = $_POST['countryname'];
		$countryAddArray['name_caps']   = strtoupper($_POST['countryname']);				
		$countryAddArray['iso1_code']      = $_POST['ciso_code'];
		$countryAddArray['country_name']      = $_POST['countryname'];
		$countryAddArray['country_status']      = '1';
		$countryObj->addCountry($countryAddArray);
		$_SESSION['msg'] = "<div class='success_msg'><span>Country added successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=country&page='.$_POST['page']);
		exit;
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please select country and ISO code</span></div>';
	}
	// main if closed
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'country');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($countryObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'country/addcountry.tpl');
unset($smarty);
?>